#include "mapdatahelper.h"
#include "log.h"


MapDataHelper::MapDataHelper( QObject *parent) :
    QObject(parent)

{

}

void MapDataHelper::paintMap()
{

}

void MapDataHelper::createLine(double x1, double y1, double x2, double y2, int directionality)
{
    //logInfo("_mapData->createLine(%lf,%lf,%lf,%lf,%d);", x1, y1, x2, y2 ,directionality);
    LineData segment;
    segment.startpoint.x = x1;
    segment.startpoint.y = y1;
    segment.endpoint.x = x2;
    segment.endpoint.y = y2;
    segment.directionality = directionality;
    mLineVector.append(segment);
}

void MapDataHelper::createArcRadian(double x, double y, double r, double angle1, double angle2)
{
   // logInfo("_mapData->createArcRadian(%lf,%lf,%lf,%lf,%lf);", x, y, r, angle1, angle2);
    ArcData segment;
    segment.arccenter.x = x;
    segment.arccenter.y = y;
    segment.angle1 = angle1;
    segment.angle2 = angle2;
    segment.radius = r;
    mArcVector.append(segment);
}

void MapDataHelper::createArcAngle(double x, double y, double r, double angle1, double angle2)
{
  //  logInfo("MapDataHelper::createArcAngle:(%lf,%lf)", x, y);
    createArcRadian(x,y,r, angle1 * M_PI / 180, angle2 * M_PI / 180);
}

void MapDataHelper::createStation(int stationId, double x1, double y1, double x2, double y2, int type)
{
    int type1 = type;
    if ((0 == stationId))
    {
        ;
        return;
    }
    /*
第0位和第1位代表站点属性
        第2位和第3位代表终点模式
        第4位和第5位代表功能类型
        第6位和第7位代表站点类型

        普通站点：  1010000
        临时停靠点：1010001
        充电点：1010003
       中转点：1010005
*/
    int stationAttr;
    int dstMode;
    int funType;
    int stationType;

    stationAttr = type1 % 100;
    type1 /= 100;
    dstMode = type1 % 100;
    type1 /= 100;
    funType = type1 % 100;
    type1 /= 100;
    stationType = type1 % 100;
  //logInfo("DxfReader::createStation:[%7d, %2d, %2d, %2d, %2d]", stationId,
  //       stationAttr, dstMode, funType, stationType);

    if ((0 != stationAttr) && (1 != stationAttr)
            && (3 != stationAttr))
    {
        return;
        ;
    }
    StationData stationData;
    stationData.startpoint.x = x1;
    stationData.startpoint.y = y1;
    stationData.endpoint.x = x2;
    stationData.endpoint.y = y2;
    stationData.id = stationId;
    stationData.attr = stationAttr;
    mStationVector.append(stationData);
}

void MapDataHelper::createStation2(int stationId, double x1, double y1, double x2, double y2, int type)
{
    int type1 = type;
    if (0 == stationId)
    {
        ;
        return;
    }
    /*
第0位和第1位代表站点属性
        第2位和第3位代表终点模式
        第4位和第5位代表功能类型
        第6位和第7位代表站点类型
*/
    int stationAttr;
    int dstMode;
    int funType;
    int stationType;

    stationAttr = type1 % 100;
    type1 /= 100;
    dstMode = type1 % 100;
    type1 /= 100;
    funType = type1 % 100;
    type1 /= 100;
    stationType = type1 % 100;
  //logInfo("DxfReader::createStation2:[%7d, %2d, %2d, %2d, %2d]", stationId,
  //       stationAttr, dstMode, funType, stationType);

    if (0 != stationAttr)
    {
        return;
    }
    StationData stationData;
    stationData.startpoint.x = x1;
    stationData.startpoint.y = y1;
    stationData.endpoint.x = x2;
    stationData.endpoint.y = y2;
    stationData.id = stationId;
    (void)stationData;
    mStationVector.append(stationData);
}
